/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.amitycs.collabdrawing.server;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;
import java.util.Arrays;
import org.amitycs.collabdrawing.Constants;

/**
 *
 * @author joe
 */
public class MultiTest {

    public static void main(String[] args) throws IOException {
        String msg = "Hello";
        InetAddress group = InetAddress.getByName(Constants.GROUP_IP);
        MulticastSocket s = new MulticastSocket(Constants.GROUP_PORT);
        s.joinGroup(group);
        DatagramPacket hi = new DatagramPacket(msg.getBytes(), msg.length(),
                group, 6789);
        s.send(hi);
        // get their responses!
        byte[] buf = new byte[1000];
        DatagramPacket recv = new DatagramPacket(buf, buf.length);
        s.receive(recv);
        for (byte b : buf)
        {
            System.out.print((char) b);
        }
        // OK, I'm done talking - leave the group...
        s.leaveGroup(group);
    }
}
